package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.AddressBook;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {


    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Select("select * from orders where status = #{pendingPayment} and order_time < #{localDateTime}")
    List<Orders> getByStatusAndOrderTime(Integer pendingPayment, LocalDateTime localDateTime);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    @Select("select count(id) from orders where order_time between #{beginTime} and #{endTime}")
    Integer totalCountByDate(LocalDateTime beginTime, LocalDateTime endTime);

    @Select("select count(id) from orders where order_time between #{beginTime} and #{endTime} and status = 5")
    Integer validCountByDate(LocalDateTime beginTime, LocalDateTime endTime);

    @Select("select sum(amount) from orders where order_time between #{begin} and #{end}")
    Double getturnover(LocalDateTime begin, LocalDateTime end);

    @Select("select count(id) from orders where order_time between #{begin} and #{end}")
    Integer getAllorder(LocalDateTime begin, LocalDateTime end);


    Integer countOrderByStatus(Integer status);
}
